#region Apache License
//
// Licensed to the Apache Software Foundation (ASF) under one or more 
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership. 
// The ASF licenses this file to you under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with 
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#endregion


using System;
using System.Collections.Generic;
using System.Text;
using IPSim.Data;
using IPSim.Core;

namespace IPSim.Devices
{
    public class Computer : IConnectable
    {
        //private bool                m_powered;
        private IPInterface         m_ipInterface;
        private EthernetInterface   m_ethernetInterface;
        private TCPInterface        m_tcpInterface;
        private UDPInterface        m_udpInterface;
        private ARPInterface        m_arpInterface;

        public Computer(IPAddress ipAddr, IPAddress subNet)
        {
            //m_powered               = false;
            m_ethernetInterface     = new EthernetInterface();
            m_ipInterface           = new IPInterface(m_ethernetInterface, ipAddr);
            m_arpInterface          = new ARPInterface(m_ethernetInterface);
            m_tcpInterface          = new TCPInterface(m_ipInterface);
            m_udpInterface          = new UDPInterface(m_ipInterface);
        }

        public void ConfigIP(IPAddress ipAddr, IPAddress subNet)
        {
            m_ipInterface.IPAddress     = ipAddr;
            m_ipInterface.SubnetMASK    = subNet;
        }

        public void SendUDPPacket(UDPPacket udpPacket, IPAddress destIP)
        {
            m_udpInterface.SendUDPPacket(udpPacket, destIP);
        }

        public void SendTCPPacket(TCPPacket tcpPacket, IPAddress destIP)
        {
            m_tcpInterface.SendTCPPacket(tcpPacket, destIP);
        }


        #region IConnectable Members

        public void Connect(IConnectable device, byte num)
        {
            m_ethernetInterface.Connect(device,1);
        }

        public void Disconnect(IConnectable device, byte num)
        {
            m_ethernetInterface.Disconnect(device,1);
        }

        public TransportEthernetFrame FrameReceiver1
        {
            get { return m_ethernetInterface.FrameReceiver1; }
        }
        public TransportEthernetFrame FrameReceiver2
        {
            get { return null; }
        }
        public TransportEthernetFrame FrameReceiver3
        {
            get { return null; }
        }
        public TransportEthernetFrame FrameReceiver4
        {
            get { return null; }
        }
        #endregion
    }
}
